#include <iostream>
#include <string>
using namespace std;
string nc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string ans;
int main(){
    int m, n, k, t, s;
    while(cin >> m >> n){
        ans = "";
        s = m;
        while(m != 0){
            k = m % n;
            t = m / n;
            if(k < 0){
                k -= n;
                t++;
            }
            m = t;
            ans.push_back(nc[k]);
        }
        for(int i = ans.length() - 1; i >= 0; i--){
            cout << ans[i];
        }
        cout << endl;
        break;
    }
    return 0;
}
